package com.markus.code.exam.tencent;
import java.util.*;
/**
 * Author:markusZhang
 * Date:Create in 2020/9/6 21:45
 * todo:
 */
public class PchDemo {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        TreeMap<String,Integer> treeMap = new TreeMap<>();
        for (int i=0;i<m;i++) {
            String temp =in.next();
            if(treeMap.containsKey(temp)) {
                treeMap.put(temp,treeMap.get(temp)+1);
            }else {
                treeMap.put(temp,1);
            }
        }
        TreeMap<Integer,List<String>> intMap = new TreeMap<>();
        for (String key : treeMap.keySet()){
            Integer count = treeMap.get(key);
            if(intMap.containsKey(count)) {
                List<String> list = intMap.get(count);
                list.add(key);
                intMap.put(count,list);
            }else {
                List<String> list = new ArrayList<>();
                list.add(key);
                intMap.put(count,list);
            }
        }
        List<Map.Entry<Integer,List<String>>> list = new ArrayList<>(intMap.entrySet());
        int maxK = n;
        int minK = n;
        for (int i =list.size()-1 ;i>=0;i--) {
            Integer count = list.get(i).getKey();
            List<String> stringList = list.get(i).getValue();
            for (int j=0;j<stringList.size();j++){
                if(maxK == 0) {
                    break;
                }
                maxK--;
                System.out.println(stringList.get(j)+" "+count);
            }
        }
        for (int i =0 ;i<list.size();i++) {
            Integer count = list.get(i).getKey();
            List<String> stringList = list.get(i).getValue();
            for (int j=0;j<stringList.size();j++){
                if(minK == 0) {
                    break;
                }
                minK--;
                System.out.println(stringList.get(j)+" "+count);
            }
        }
    }
}

